<?php

class AdminTag extends Admin{

	public $useDB = array("Tag");

	public function search($kword){
		$this->doNotInit = true;
		$except = $_POST["except"];
		$except = $except ? $except : array(0);

		$tags = $this->dbTag->find(array(
			"select" => array("t.id", "t.name"),
			"from" => "tags t INNER JOIN tag_categories tc ON t.category_id=tc.id",
			"conditions" => array(
				"OR" => array(
					"t.name LIKE" => "'%$kword%'",
					"tc.name" => $kword
				),
				"AND" => array(
					"t.id NOT IN" => "(".implode(",", $except).")"
				)
			),
			"order" => "t.name"
		));

		echo json_encode($tags);
	}

}